package com.bole.dao;

import com.bole.pojo.TbMenuDo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

@Transactional
public interface MenuDao extends JpaRepository<TbMenuDo,Long> {
    @Query(value = "select DISTINCT m.* from tb_menu m\n" +
            "    LEFT JOIN menu_role rm on m.id=rm.menu_id\n" +
            "    left JOIN tb_role r on rm.role_id=r.id\n" +
            "    LEFT JOIN admin_role pr on r.id=pr.role_id\n" +
            "    LEFT JOIN tb_admin p on pr.admin_id=p.id\n" +
            "     where p.id = ?1" , nativeQuery = true)
    List<TbMenuDo> getMenuByUserId(Long id);
    @Query("from TbMenuDo where id = ?1")
    TbMenuDo getById(Long id);
}
